Theoretically, the use of the static
keyword on the size of an array parameter means you can assume that only arrays of at least that
size will be passed as arguments to the function. I.e. a function parameter of int my_array[static 10]
means that my_array
will always be at least 10 elements long. If it is not, the behavior is undefined.
In practice, the use of static
on the size of an array parameter means the compiler might issue a warning if a noncompliant array is
passed to the function - a warning that might or might not be ignored. Therefore, in practice the use of static
on an array parameter’s
size merely lends a false sense of security, and static
should not be used in this context.
Note that for some compiler/processor combinations, more efficient code can be generated when static
is used, but these combinations
are limited, and the benefit does not outweigh the cost.
Noncompliant code example
int total (int size, int my_array[static 10]) {...}
Compliant solution
int total (int size, int my_array[10]) {...}